//
//  HMNavgationController.swift
//  GuoGuo
//
//  Created by 艾小新 on 16/8/1.
//  Copyright © 2016年 xiaoxin. All rights reserved.
//

import UIKit

class HMNavgationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    ///  重写方法 改变左返回按钮统一设置，并且判断如果是第二级就返回上一级的名字，剩下的是返回
    ///
    ///  - parameter viewController:
    ///  - parameter animated:
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        // 如果大于1 就显示上一级的标题
        
        if childViewControllers.count > 0 {
            
            var title = "返回"
            
            if childViewControllers.count == 1 {
                title = childViewControllers.first?.title ?? "返回"
            }
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: title, target: self, action: #selector(returnController))
            
        }
        super.pushViewController(viewController, animated: true)
    
    }
    
    ///  pop事件
    func returnController() {
        
        popViewControllerAnimated(true)
        
    }
    
    
    
    
    
    
    
    



    
    
    
    
    
    
    
    
    
}
